local M = require "packages/mamashengde/record/Made"

local youlong = fk.CreateSkill {
  name = "shine__youlong",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable {
  ["shine__youlong"] = "游龙",
  [":shine__youlong"] = "锁定技，你造成的伤害改为冰冻伤害，受到冰冻伤害的角色直到其下个回合结束：摸牌数-1，你+1，且计算距离时+1，你-1，且不能响应你使用的牌。",
  ["@shine__youlong"] = "游龙",
}

youlong:addEffect(fk.PreDamage, {
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(youlong.name) and data.from == player and data.damageType ~= fk.IceDamage
  end,
  on_refresh = function(self, event, target, player, data)
    data.damageType = fk.IceDamage
  end,
})

youlong:addEffect(fk.Damaged, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(youlong.name) and target and data.damageType == fk.IceDamage
  end,
  --on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(target, "@shine__youlong", target:getMark("@shine__youlong") + 1)
    room:setPlayerMark(player, "shine__youlong", player:getMark("shine__youlong") + 1)
  end,
})

youlong:addEffect(fk.DrawNCards, {
  can_refresh = function(self, event, target, player, data)
    return target == player and (player:getMark("@shine__youlong") ~= 0 or player:getMark("shine__youlong") > 0)
  end,
  on_refresh = function(self, event, target, player, data)
    data.n = data.n - player:getMark("@shine__youlong") + player:getMark("shine__youlong")
  end,
})

youlong:addEffect(fk.TurnEnd, {
  can_refresh = function(self, event, target, player, data)
    return target and target:getMark("@shine__youlong") ~= 0 and player
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local n = math.max(player:getMark("shine__youlong") - target:getMark("@shine__youlong"), 0)
    room:setPlayerMark(player, "shine__youlong", n)
    room:setPlayerMark(target, "@shine__youlong", 0)
  end,
})

youlong:addEffect("distance", {
  correct_func = function(self, from, to)
    if from:getMark("@shine__youlong") ~= 0 then
      return from:getMark("@shine__youlong")
    elseif from:getMark("shine__youlong") ~= 0 then
      return -from:getMark("shine__youlong")
    end
  end,
})

youlong:addEffect(fk.CardUsing, {
  can_trigger = function(self, event, target, player, data)
    return player:getMark("shine__youlong") > 0 and table.find(player.room.alive_players, function (p)
        return p:getMark("@shine__youlong") ~= 0
      end)
  end,
  on_use = function(self, event, target, player, data)
    data.disresponsiveList = data.disresponsiveList or {}
    for _, p in ipairs(player.room.alive_players) do
      if p:getMark("@shine__youlong") ~= 0 then
        table.insertIfNeed(data.disresponsiveList, p)
      end
    end
  end,
})

return youlong